#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL dp[maxn][2];
LL ksm(LL a,LL k){
   LL res=1;
   while(k){
      if(k&1) res=res*a%mod;
      a=a*a%mod;
      k>>=1;
   }return res%mod;
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL t;cin>>t;
    while(t--){
        LL n,m;cin>>n>>m;
        memset(dp,0,sizeof(dp));
        LL x=ksm(2,n-1);
        if(n%2==0){
            dp[0][0]=1;
            LL ans=0;
            for(LL i=1;i<=m;i++){
                ans=(ans%mod+(dp[i-1][0]%mod*ksm(2,n*(m-i))%mod)%mod )%mod;
                dp[i][0]=(dp[i-1][0]%mod*(x-1)%mod)%mod;
            }
            ans=(ans%mod+dp[m][0]%mod)%mod;
            cout<<ans<<"\n";
        }
        else{
            dp[0][0]=1;
            for(LL i=1;i<=m;i++){
                dp[i][1]=(dp[i-1][0]%mod+dp[i-1][1]%mod)%mod;
                dp[i][0]=((dp[i-1][0]%mod+dp[i-1][1]%mod)*x%mod)%mod;
            }
            cout<<(dp[m][0]%mod+dp[m][1]%mod)%mod<<"\n";
        }
    }
   	return 0;
}
